//
// Description: 104. 货仓选址
// Created by Loading on 2022/6/5.
//

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 10;

int a[N];

/* 绝对值不等式 */
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    sort(a, a + n);

    int res = 0;
    for (int i = 0; i < n; ++i) {
        res += abs(a[i] - a[n / 2]);
    }

    cout << res << endl;

    return 0;
}